#ifndef _GWBASE_BASE_STRING_UTIL_H_
#define _GWBASE_BASE_STRING_UTIL_H_

#include <assert.h>
#include <stdio.h>
#include <string>
#include <ostream>
#include <vector>
#include <stdarg.h>

#include "gwbase/base/slice.h"

namespace dicom {

// Helper class to format small string with single parameter
// Usage:
//  std::cout << Fmt("%02d", 123);
//  std::string s = Fmt("%02llx", 223LL).c_str();
class Fmt {
  static const int kMaxLen = 128;

 public:
  template <typename T>
  Fmt(const char* fmt, T t) {
    snprintf(data_, kMaxLen, fmt, t);
  }

  const char* c_str() const { return data_; }
  std::string str() const { return std::string(data_); }

 private:
  char data_[kMaxLen];
};

inline std::ostream& operator<<(std::ostream& os, const Fmt& f) {
  os << f.c_str();
  return os;
}

extern void SplitToLines(const std::string& src, std::vector<Slice>* out);

extern std::string LowerString(const std::string& src);
extern void InplaceLowerString(std::string& str);

extern void StringPrintf(std::string* result, const char* fmt, ...)
    __attribute__((__format__(__printf__, 2, 3)));

extern std::string StringPrintf(const char* fmt, ...)
    __attribute__((__format__(__printf__, 1, 2)));

extern void StringPrintfV(std::string* result, const char* fmt, va_list ap);
}

#endif  // _GWBASE_BASE_STRING_UTIL_H_
